package secondBrain.gaslog.businessentities;

import java.util.Date;

public class GasRecord {
	private Integer _id;
	private Date _createTime;
	private Date _recordDate;
	private Double _litres;
	private Double _total;
	private Double _gasPrice;
	private Double _priceDiscount;
	private Double _discount;
	private Double _distance;
	private String _comment;

	public GasRecord() {

		setCreateTime(new Date());
		setRecordDate(new Date());
	}

	public Integer getId() {

		return _id;
	}

	public void setId(int id) {

		_id = id;
	}

	public Date getRecordDate(){
		
		return _recordDate;
	}
	
	public void setRecordDate(Date recordDate){

		_recordDate = recordDate;
	}
	
	public Double getDistance() {

		return _distance;
	}

	public void setDistance(Double distance) {

		_distance = distance;
	}

	public Double getLitres() {

		return _litres;
	}

	public void setLiters(Double litres) {

		_litres = litres;
	}

	public Double getGasPrice() {

		return _gasPrice;
	}

	public void setGasPrice(Double price) {

		_gasPrice = price;
	}

	public Double getPriceDiscount() {

		return _priceDiscount;
	}

	public void setPriceDiscount(Double discount) {

		_priceDiscount = discount;
	}

	public Double getTotal() throws GasLogCalculationException {

		if (_total == null) {

			calcualteTotal();
		}

		return _total;
	}

	public Date getCreateTime() {

		return _createTime;
	}

	public void setCreateTime(Date createTime) {

		_createTime = createTime;
	}

	public Double getDiscount() {

		return _discount;
	}

	public void setDiscount(Double discount) {

		_discount = discount;
	}

	public void setComment(String comment) {

		_comment = comment;
	}

	public String getComment() {

		return _comment;
	}

	private void calcualteTotal() throws GasLogCalculationException {
		if ((_litres != null) && (_gasPrice != null)
				&& (_priceDiscount != null) && (_discount != null)) {

			_total = _litres * (_gasPrice - _priceDiscount) - _discount;
		} else {

			_total = null;
			throw new GasLogCalculationException("Invalid properties");
		}
	}
}
